/**
 * Created by Administrator on 2017/8/18 0018.
 */

var audit;
if (!audit) {
    audit = {};
}

audit.operateFormatter = function (value, row, index) {
    return [
        '<a class="updateAudit1" href="javascript:void(0)" >审核通过</a>' +
        '&nbsp;&nbsp;' +
        '<a class="updateAudit2" href="javascript:void(0)" >审核不通过</a>' +
        '&nbsp;&nbsp;' +
        '<a class="remove" href="javascript:void(0)" style="color: red">删除待审核商家</a>'
    ].join('');
};

window.operateEventes = {
    'click .updateAudit1': function (e, value, row) {
        showModel("auditBusiness-div", function () {
            $("#updateId").val(row.id);
            $("#audits").val(1);
            $("#emergencyContact").val(row.emergencyContact);
            $("#emergencyTel").val(row.emergencyContactTel);
            var path = File_Download_Url;
            // var logo = path + row.bussLogo;
            var licnese = path + row.bussLicnese;
            var store = path + row.storePic;
            var shop = path + row.shopPic;
            var legalCardPic = path + row.legalCardPic;
            var service = path + row.serviceLince;
            // $("#logos").attr("src", logo);
            $("#licneses").attr("src", licnese);
            $("#licneses").attr("img-path", row.bussLicnese);
            $("#stores").attr("src", store);
            $("#shops").attr("src", shop);
            $("#legalCardPicUpdate").attr("src", legalCardPic);
            $("#services").attr("src", service);

            $("#stores").attr("img-path", row.storePic);
            $("#shops").attr("img-path", row.shopPic);
            $("#legalCardPicUpdate").attr("img-path", row.legalCardPic);
            $("#services").attr("img-path", row.serviceLince);
            var getTypeId = function () {
                $.post($().AbsUrlParse("/web/business/queryByTypeId"), null, function (id) {
                    var select = $("#busType");
                    select.empty();
                    select.append('<option value="0">-商家分类-</option>');
                    if (id.res.code == 40000) {
                        var allData = id.res.data;
                        for (var i = 0; i < allData.length; i++) {
                            select.append('<option value="' + allData[i].id + '">' + allData[i].typeName + '</option>');
                            $("#busType").val(row.bussTypeId);
                        }
                    }
                });
            };
            getTypeId();
        });
    },
    'click .updateAudit2': function (e, value, row) {
        showModel("auditReason-div", function () {
            $("#ids").val(row.id);
            $("#audit").val(2);
            $("#reason").val('');
        });
    },
    'click .remove': function (e, value, row) {
        comment.showOperationTips("确定删除吗？", function () {
            $.post($().AbsUrlParse('/web/business/updateStatus'), {id: row.id, state: 0}, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("删除成功");
                        var table = $("#table");
                        table.bootstrapTable("refresh");
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        });
    }
};

detailsData = function (value, row, index) {
    return [
        '<a class="details" href="javascript:void(0)" >详细资料</a>'
    ].join('');
};

window.operateEvente = {
    'click .details': function (e, value, row) {
        showModel("auditBusinessDetails-div", function () {

            var path = File_Download_Url;
            var legalCardPic = path + row.legalCardPic;
            var licnese = path + row.bussLicnese;
            var store = path + row.storePic;
            var shop = path + row.shopPic;
            var card = path + row.idCard;
            var service = path + row.serviceLince;
            $("#legalCardPic").attr("src", legalCardPic);
            $("#licnese").attr("src", licnese);
            $("#store").attr("src", store);
            $("#shop").attr("src", shop);
            $("#idCard").attr("src", card);
            $("#service").attr("src", service);
        });
    }
};

var queryAduitBusiness = function () {
    var account = $("#account").val();
    var name = $("#nameBusiness").val();
    var tel = $("#tel").val();
    var cityName = $("#cityName").val();
    var address = $("#address").val();
    var url = $().AbsUrlParse("/web/business/queryBusinessAudit?businessName=" + name + "&account=" + account + "&telephone=" + tel + "&cityName=" + cityName + "&address=" + address);
    var table = $("#table");
    table.bootstrapTable("refresh", {url: url});
};

/**
 *执行修改保存操作
 * */
bindClick("button[data-event=submit-updateAuditReason]", function () {
    var id = $("#ids").val();
    var audit = $("#audit").val();
    var reason = $("#reason").val();
    $.post($().AbsUrlParse("/web/business/updateAudit"), {id: id, audit: audit, reason: reason}, function (res) {
        if (res.state && res.res.code == 40000) {
            hint('操作成功！');
            //关闭model方法
            closeModel('auditReason-div');
            var table = $("#table");
            table.bootstrapTable("refresh");
        } else {
            if (res.state == false) {
                hint(res.msg);
            } else {
                hint(res.res.msg);
            }
        }
    });
});


/**
 *执行修改保存操作
 * */
bindClick("button[data-event=submit-auditBusiness]", function () {

    var store = $("#stores").attr("img-path");
    $("#busStores").val(store);

    var shop = $("#shops").attr("img-path");
    $("#busShop").val(shop);

    var legalCardPic = $("#legalCardPicUpdate").attr("img-path");
    $("#legalCardPicBus").val(legalCardPic);

    var service = $("#services").attr("img-path");
    $("#busService").val(service);

    var path = $("#licneses").attr("img-path");
    $("#busLicnese").val(path);

    var form = $("#updateAuditBusinessFrom");
    var v = form.valid();
    if (v == false) {
        return false;
    }
    var params = form.formToArray();
    $.post($().AbsUrlParse('/web/business/updateAudit'), params, function (data) {
        if (data.state == true) {
            if (data.res.code == 40000) {
                hint("审核通过");
                var table = $("#table");
                table.bootstrapTable("refresh");
                closeModel("auditBusiness-div")
            } else {
                hint(data.res.msg);
            }
        } else {
            hint(data.msg);
        }
    });
});

function enlargeImage(value) {
    showModel("detailImage-div", function () {
        var imgs = '<image src=' + value.src + ' style="height:500px" />';
        $("#image").html(imgs);
    })
}

